package id.net.iconpln.bb.client.view;

import id.net.iconpln.bb.client.model.BbEntryPJBBBean;
import id.net.iconpln.bb.client.model.PageBbPemasokBean;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.binding.FormBinding;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.GroupingStore;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup;
import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.RowNumberer;
import com.extjs.gxt.ui.client.widget.layout.FitData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.user.client.Element;

public class PageBbPencatatanPengeluaran extends LayoutContainer {
	
	private EditorGrid<BbEntryPJBBBean> grid;
	private GroupingStore<BbEntryPJBBBean> store;
	  String dataGeoString;
	  String tglTerimaFile ;
	  int var;
	  String url;
	  String params;
	  String tglTerima;
//	  BbEntryPJBBBean plant = new BbEntryPJBBBean();
	  ColumnModel cm;
	  Button btinsert; 
	  Button btdelete;
	  Button btupdate;
	  Button btcetak;
	  boolean checkstore;
	  List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
      ColumnConfig nojbb = new ColumnConfig();
      ColumnConfig volpjbbb = new ColumnConfig();
      ColumnConfig kalori = new ColumnConfig();
      ColumnConfig lot = new ColumnConfig();
      ColumnConfig harga_ton = new ColumnConfig();
      ColumnConfig harga_sesuai = new ColumnConfig();
      ColumnConfig rpnilaikontrak = new ColumnConfig();
      ColumnConfig vol_tahun = new ColumnConfig();
      ColumnConfig keb_tahun = new ColumnConfig();
      ColumnConfig tahun = new ColumnConfig();
      ColumnConfig jaminan = new ColumnConfig();
      ColumnConfig masaberlaku = new ColumnConfig();
      ColumnConfig jenispengiriman = new ColumnConfig();
      ToolBar toolbar;
	  
	  @Override  
	  protected void onRender(Element parent, int index) {  
	    super.onRender(parent, index);  
	    setLayout(new FitLayout());
		add(createExpander(), new FitData(5));
	  }  
	  private ContentPanel createExpander() {  
		 
		    store = new GroupingStore<BbEntryPJBBBean>();
//		    store.groupBy("jenispengiriman");
//		    
//		    store.setMonitorChanges(true);  
//		    store.add(TestData.getPJBB()); 
		    
		    RowNumberer rn = new RowNumberer();  
		    rn.setWidth(30);
		    
		    nojbb.setId("nopjbb");
		    nojbb.setHeader("Unit");
		    nojbb.setWidth(150);
		    nojbb.setAlignment(HorizontalAlignment.LEFT);
		    nojbb.setFixed(true);
		    nojbb.setGroupable(false);
		    nojbb.setMenuDisabled(true);
		    nojbb.setResizable(false);
		    nojbb.setSortable(false);
			
			volpjbbb.setId("volpjbb");
			volpjbbb.setHeader("Tanggal");
			volpjbbb.setWidth(100);
			volpjbbb.setAlignment(HorizontalAlignment.LEFT); 
			volpjbbb.setFixed(true);
			volpjbbb.setGroupable(false);
			volpjbbb.setMenuDisabled(true);
			volpjbbb.setResizable(false);
			volpjbbb.setSortable(false);
			
			
			kalori.setId("kalori");
			kalori.setHeader("Volume Pengajuan");
			kalori.setWidth(100);
			kalori.setAlignment(HorizontalAlignment.LEFT);
			kalori.setFixed(true);
			kalori.setGroupable(false);
			kalori.setMenuDisabled(true);
			kalori.setResizable(false);
			kalori.setSortable(false);
			
			lot.setId("lot");
			lot.setHeader("Volume Pakai");
			lot.setWidth(100);
			lot.setAlignment(HorizontalAlignment.LEFT);
			lot.setFixed(true);
			lot.setGroupable(false);
			lot.setMenuDisabled(true);
			lot.setResizable(false);
			lot.setSortable(false);
			
			harga_ton.setId("hargarpton");
			harga_ton.setHeader("Satuan");
			harga_ton.setWidth(100);
			harga_ton.setAlignment(HorizontalAlignment.LEFT);
			harga_ton.setFixed(true);
			harga_ton.setGroupable(false);
			harga_ton.setMenuDisabled(true);
			harga_ton.setResizable(false);
			harga_ton.setSortable(false);
			
			tahun.setId("hargarpton");
			tahun.setHeader("Keterangan");
			tahun.setWidth(100);
			tahun.setAlignment(HorizontalAlignment.LEFT);
			tahun.setFixed(true);
			tahun.setGroupable(false);
			tahun.setMenuDisabled(true);
			tahun.setResizable(false);
			tahun.setSortable(false);
			
			
			
			columns.add(rn);
			columns.add(nojbb);
			columns.add(volpjbbb);
			columns.add(kalori);
//		    columns.add(lot);  
		    columns.add(harga_ton); 
		    columns.add(tahun);  
		    
		    
		    cm = new ColumnModel(columns);
		    
//		    GroupingView summary = new GroupingView();  
//		    summary.setShowGroupedColumn(false);
//		    summary.setGroupRenderer(new GridGroupRenderer() {  
//		        public String render(GroupColumnData data) {  
//		          String f = cm.getColumnById("jenispengiriman").getHeader();  
////		          String l = data.models.size() == 1 ? "Item" : "Unit";  
//		          return f + ": " + data.group + " (" + data.models.size() + ")</span>";
////		          return f + ": " + data.group + " (" + data.models.size() + " " + l + ")</span>";
//		        }  
//		      }); 
		    
		    
		    
		    grid = new EditorGrid<BbEntryPJBBBean>(store, cm);  
//		    grid.setView(summary);
		    grid.setStripeRows(true);
//		    final GridSelectionModel<BbEntryPJBBBean> csm = new GridSelectionModel<BbEntryPJBBBean>();
//	        grid.setSelectionModel(csm);
	        
	        btinsert = new Button("Simpan", new SelectionListener<ButtonEvent>() {  
			      @Override  
			      public void componentSelected(ButtonEvent ce) {
			    	 
			      }  
			    });  
			    
//	        btinsert.setIcon(IconHelper.createStyle("icon-add"));
	        btinsert.setEnabled(false);
		    
		   btupdate = new Button("Ubah", new SelectionListener<ButtonEvent>() {  
			      @Override  
			      public void componentSelected(ButtonEvent ce) {
			    	  
			      }  
			    });  
//		   btupdate.setIcon(IconHelper.createStyle("icon-edit-record"));
		   btupdate.setEnabled(false);
		   
		   btdelete = new Button("Delete", new SelectionListener<ButtonEvent>() {  
			      @Override  
			      public void componentSelected(ButtonEvent ce) {
			    	  
			      }  
			    });  
//		   btdelete.setIcon(IconHelper.createStyle("icon-delete"));
		   btdelete.setEnabled(false);
			
		   btcetak = new Button("Cetak", new SelectionListener<ButtonEvent>() {  
			      @Override  
			      public void componentSelected(ButtonEvent ce) {
			    	  
			      }  
			    });  
//		   btdelete.setIcon(IconHelper.createStyle("icon-delete"));
		   btcetak.setEnabled(false);
			
		    toolbar = new ToolBar();
		    
			toolbar.add(btcetak);
//		    
//			toolbar.add(btinsert);
//			toolbar.add(new SeparatorToolItem());
//		    toolbar.add(btupdate);
//			toolbar.add(new SeparatorToolItem()); 
//			toolbar.add(btdelete);
			
	        
	        
		    ContentPanel cp = new ContentPanel();  
		    cp.setHeaderVisible(false);
		    cp.setLayout(new FitLayout());
		    cp.add(grid);
//		    cp.setTopComponent(toolbar);
		  
		    return cp;  
		  }
}